FastClick.attach(document.body);
function GetUrlString(name){
  var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  var s=window.location.search.substr(1).match(reg);
  var h = window.location.hash.substr(1).match(reg);
  if(s){return unescape(s[2]);}
  if(h){return unescape(h[2]);}
  return "";
};

//新房列表信息
var type = GetUrlString("type"),houseListData;
if(type == "oldHouse"){
  houseListData = JSON.parse(localStorage.getItem("oldListData"));
}else{
  houseListData = JSON.parse(localStorage.getItem("houseListData"));
}


var thisPoint = localStorage.getItem("point").split(","),lat = thisPoint[0],lng = thisPoint[1];
var map = new BMap.Map("mapMark");
var point = new BMap.Point(lng,lat);
map.centerAndZoom(point, 13);

// 编写自定义函数,创建标注
// function addMarker(point){
//   var marker = new BMap.Marker(point);
//   map.addOverlay(marker);
// }

// $.each(houseListData.list,function(index,info){
//   var point = new BMap.Point(info.longitude,info.latitude);
//   addMarker(point);
// });

//自定义覆盖物
function ComplexCustomOverlay(point, text){
  this._point = point;
  this._text = text;
}
ComplexCustomOverlay.prototype = new BMap.Overlay();
ComplexCustomOverlay.prototype.initialize = function(mp){
  this._map = mp;
  var div = this._div = document.createElement("div");
  div.className = "mapText";
  var span = this._span = document.createElement("span");
  div.appendChild(span);
  span.appendChild(document.createTextNode(this._text));      
  var that = this;
  map.getPanes().markerPane.appendChild(div);
  return div;
}
ComplexCustomOverlay.prototype.draw = function(){
  var map = this._map;
  var pixel = map.pointToOverlayPixel(this._point);
  this._div.style.left = pixel.x - 10 + "px";
  this._div.style.top  = pixel.y - 30 + "px";
}

$.each(houseListData.list,function(index,info){
  var myCompOverlay = new ComplexCustomOverlay(new BMap.Point(info.longitude,info.latitude),info.name);
  map.addOverlay(myCompOverlay);
});

